package com.sta.oldman.utils;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class VerificationCodeService {
    @Resource
    private StringRedisTemplate stringRedisTemplate; // 使用 StringRedisTemplate

    public void saveCode(String email, String code) {
        stringRedisTemplate.opsForValue().set(
                email,
                code,
                5,
                TimeUnit.MINUTES
        );
    }

    public boolean verifyCode(String email, String inputCode) {
        String storedCode = stringRedisTemplate.opsForValue().get(email); // 直接获取原始字符串
        return storedCode != null && storedCode.equals(inputCode);
    }
}